package com.cdh.edu.controller.api;

import com.cdh.edu.entity.Course;
import com.cdh.edu.entity.vo.ChapterVo;
import com.cdh.edu.entity.vo.WebCourseQueryVo;
import com.cdh.edu.entity.vo.WebCourseVo;
import com.cdh.edu.service.ChapterService;
import com.cdh.edu.service.CourseService;
import com.cdh.utils.result.Restful;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author by cdh
 * @description:
 * @Date: Created in 11:03 on 2021/2/26
 */
@Api(tags = "课程")
@RestController
@RequestMapping("api/edu/course")
@CrossOrigin
public class ApiCourseController {

    @Autowired
    private CourseService courseService;
    @Autowired
    private ChapterService chapterService;

    @ApiOperation(value = "获取讲师详情")
    @GetMapping("list")
    public Restful pageList(
            @ApiParam(value = "查询对象",required = true)
            WebCourseQueryVo webCourseQueryVo
            ){
        List<Course> courseList = courseService.webSelectList(webCourseQueryVo);
        return Restful.ok().data("courseList",courseList);
    }

    @ApiOperation(value = "根据ID查询课程")
    @GetMapping("get/{courseId}")
    public Restful getCourseById(
            @ApiParam(value = "课程ID",required = true)
            @PathVariable String courseId
    ){
        // 查询课程信息和讲师信息
        WebCourseVo webCourseVo = courseService.selectWebCourseVoById(courseId);

        // 查询当前课程的嵌套和课时信息
        List<ChapterVo> chapterVoList = chapterService.getChapterVideoByCourseId(courseId);

        return Restful.ok().data("course",webCourseVo).data("chapterVoList",chapterVoList);
    }
}
